#include <math.h>
#include <string>
#include <cstdlib>
#include <stdio.h>
#include <iostream>
#include "Constants.h"
#include "EllipticIntegrals.h"
#include "Exception.h"
#include "Log.h"



using namespace std;


extern Log* plog;
float G(float r, float z, float ri, float zi){
    
   float k_double = 0;
   float k = 0;
   float res = 0;
   

   
   k_double = fmin(   (4*r*ri)/(   pow(r+ri,2)+pow(z-zi,2)) , 0.9999999 );
   k = sqrt(k_double);
   
	//for correct calculation in point (r,z,r,z)
   res = ((8 * Pi) / c_light) * (sqrt(r * ri) / k) * ((1 - k_double / 2) * K(k) - E(k));
   if (res != res) {
        plog->writeErr("green function");
    }

           
   return res;
  
};


